package com.gitee.neuray.security.wb.ribs.controller;

import com.alibaba.fastjson.JSONObject;
import com.gitee.neuray.security.common.msg.ListRestResponse;
import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import com.gitee.neuray.security.common.msg.TableResultResponse;
import com.gitee.neuray.security.common.util.Query;
import com.gitee.neuray.security.wb.ribs.biz.*;
import com.gitee.neuray.security.wb.ribs.vo.ApproveRoleVo;
import com.gitee.neuray.security.wb.ribs.vo.ClfVo;
import com.gitee.neuray.security.wb.ribs.vo.CyfVo;
import com.gitee.neuray.security.wb.ribs.vo.RibsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("approvePC")
public class ApprovePCController {

    @Autowired private ApproveRoleBiz approveRoleBiz;
    @Autowired private RibsBiz ribsBiz;
    @Autowired private ClfBiz clfBiz;
    @Autowired private CyfBiz cyfBiz;
    @Autowired private JtfBiz jtfBiz;
    @Autowired private WechatBiz wechatBiz;

    /**
     * 分页获取列表
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "page", method = RequestMethod.GET)
    public TableResultResponse queryPage(@RequestParam Map<String, Object> params, HttpServletRequest request) {

        String userId = request.getHeader("userid");
        //params.put("staffId",userId);
        // 查询列表数据
        Query query = new Query(params);
        return approveRoleBiz.page(query,userId,"query");

    }
    /**
     * 分页获取列表
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "approveQuery", method = RequestMethod.GET)
    public TableResultResponse approveQuery(@RequestParam Map<String, Object> params, HttpServletRequest request) {

        String userId = request.getHeader("userid");
        //params.put("staffId",userId);
        // 查询列表数据
        Query query = new Query(params);
        String type = "approve";
        if("wechat".equals(params.get("type"))){
            type = "wechat";
        }
        return approveRoleBiz.page(query,userId,type);
    }

    /**
     * 根据条件查询，不分角色
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "approveByDetail", method = RequestMethod.GET)
    public ListRestResponse<List<RibsVo>> approveByDetail(@RequestParam Map map, HttpServletRequest request) {
        RibsVo ribsVo = JSONObject.parseObject(JSONObject.toJSONString(map),RibsVo.class);
        return ribsBiz.approveByDetail(ribsVo);
    }
    @RequestMapping(value = "approve",method = RequestMethod.PUT)
    public ObjectRestResponse<ApproveRoleVo> approve(@RequestBody List<RibsVo> ribsVos,HttpServletRequest request){
        for(RibsVo ribsVo : ribsVos){
            ribsBiz.approveRibs(ribsVo,request);
        }

        return new ObjectRestResponse<ApproveRoleVo>().rel(true);
    }

    @RequestMapping(value = "queryDetail",method = RequestMethod.GET)
    public ObjectRestResponse<Map<String,Object>> queryDetail(@RequestParam Map<String,Object> map){
        RibsVo ribsVo = JSONObject.parseObject(JSONObject.toJSONString(map),RibsVo.class);
        return new ObjectRestResponse<Map<String,Object>>().data(ribsBiz.queryDetail(ribsVo)).rel(true);
    }

}
